Skip to content

Conversation

avallete
Copy link
Member

@avallete avallete commented Oct 7, 2025

🔍 Description

Rework and migration of: supabase/postgrest-js#632 to the new monorepo

We want to first release the types inference changes first for two reasons:

  1. There still might break some codebases even if it has been tested here that it's mostly retro-compatible.
  2. Another possible issue would be this change to increase too much the type inference time / recursion level. This can also hardly be detected by tests a PR is in draft here to see how we could introduce some performance testing for the types inference to avoid regressions in future

What changed?

  • This PR change the current type inference to handle embeded function inference within the queries / rpc and prepare to work with the new postgrest-meta introspection which will allows setof returning function to be properly handled cf this PR. Those changes will include:
    • A new SetofOptions fields in the functions definitions so we can loop for relationship in select embed functions
    • The Functions are back to an union for each function definition, since a function overload, can define a different return type than the original (previously it was assumed that a function could take different args but should always return the same value)
    • We now generate in advance postgrest functions calls errors when possible allowing users to see in advance when postgrest won't be able to discriminate between two functions with similar calls, or when a function can't be used as embed function.
  • It also add a lot of tests cases around function definitions and calls to improve the coverage for it. This also allows to ensure there is no regressive behavior between this "new typescript inference code" working with "old generated types" and to ensure that with the "new generated types" we have better type inferences (errors for invalid functions calls, args checking, functions overload definition, ...)
  • Also had to refactor the way we share types between postgrest-js and supabase-js to reduce duplication but maintain consitency.
    • Isolated the new rpc typing logic into it's own file, also extracted the other types previously duplicated within supabase-js so we can just copy / paste the files over within supabase-js/src/lib/rest/types/common to ensure consistency.
    • Added a postbuild script to postgrest-js that takes those common types used in both packages and copy them over. Making postgrest-js the source of truth, and supabase-js a derivative.

Why was this change needed?

  • Currently we don't handle neither functions embedding or rpc calls really properly. With those type inference changes, along with the new generated types, we'll have a much more closer to runtime type generation.

This will close those (some more might be in backlog):

Closes #1366 #1365 #1364 #1641

🔄 Breaking changes

  • None (hopefully)

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

- Keeps the new tests, use the old types, ensure the new behavior types are retro-compatibles
To do so we've first checkout src/ to match current master ran the test and extracted all errors
Then restored the new src/ ran the tests extracted all errors
Then, compare the both to ensure they was no differences (only one is about filtering after rpc call which is expected)

Commented out the failing scenarios for now, they'll be uncommented when we release the new postgres-meta version
with the new SetofOptions available, at this point they can all be uncommented and will pass
@coveralls
Copy link

coveralls commented Oct 7, 2025

Coverage Status

coverage: 95.455% (+13.0%) from 82.5%
when pulling dbebb30 on feat/add-embeded-functions-type-inference
into 1397c9b on master.

@avallete avallete force-pushed the feat/add-embeded-functions-type-inference branch from dac034f to 4b3ba3c Compare October 7, 2025 15:45
@avallete avallete marked this pull request as ready for review October 7, 2025 19:17
@avallete avallete requested review from a team as code owners October 7, 2025 19:17
Copy link

pkg-pr-new bot commented Oct 7, 2025

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@1632

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@1632

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@1632

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@1632

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@1632

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@1632

commit: dbebb30

@avallete avallete merged commit 00c4a11 into master Oct 8, 2025
24 checks passed
@avallete avallete deleted the feat/add-embeded-functions-type-inference branch October 8, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supabase type error when querying computed field of rpc result
4 participants